<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Mailer
 *
 * @author Santiago Benítez 
 */
class Mailer {

    /**
     * Función para enviar correos electrónicos usando php mailer
     * @author Santiago Benítez
     * @param type $to
     * @param type $subject
     * @param type $body
     * @param type $from
     * @param type $fromName
     */
    public static function enviarEmail($to, $subject, $body, $from = "inmobiliariaimbabura@gmail.com", $fromName = "PUCESI") {
        if (true) {
            Yii::app()->mailer->Host = "smtp.gmail.com";
            Yii::app()->mailer->IsSMTP();
            Yii::app()->mailer->Port = "465";
            Yii::app()->mailer->SMTPAuth = true;
            Yii::app()->mailer->SMTPSecure = "ssl";
            Yii::app()->mailer->Username = "inmobiliariaimbabura@gmail.com";
            Yii::app()->mailer->Password = "imbabura1";
            Yii::app()->mailer->From = $from;
            Yii::app()->mailer->FromName = $fromName;
            Yii::app()->mailer->AddReplyTo($from);
            Yii::app()->mailer->IsHTML(true);
            if (is_array($to)) {
                foreach ($to as $t) {
                    Yii::app()->mailer->AddAddress($t);
                }
            } else {
                Yii::app()->mailer->AddAddress($to);
            }
            Yii::app()->mailer->Subject = $subject;
            Yii::app()->mailer->Body = $body;
            if (!Yii::app()->mailer->Send()) {
             
//                throw new Exception('Error enviando el correo');  
                 Yii::app()->user->setFlash('error', "No se envio el correo de confirmacion.");
            } else {
                
            }
        }
    }

}

?>
